
/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package com.gaoxk.cxf.service.s30062000020;

import com.alibaba.fastjson.JSONObject;
import com.gaoxk.redisdemo.Limitinfo;
import com.gaoxk.redisdemo.RedisLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.jws.WebService;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;


/**
 * This class was generated by Apache CXF 3.5.6
 * 2023-07-12T09:20:52.564+08:00
 * Generated source version: 3.5.6
 *
 */
@Service(value = "ESBServerSoapEndpointImpl1")
@WebService(
                      serviceName = "S30062000020",
                      portName = "ESBServerSoapEndpoint",
                      targetNamespace = "http://esb.dcitsbiz.com/services/30062000020/wsdl",
                      wsdlLocation = "file:D:/xnewtech/20230830/ceshifiler/wsdl/30062000020/30062000020.wsdl",
                      endpointInterface = "com.gaoxk.cxf.service.s30062000020.ESBServerPortType")
@Scope(value = "prototype")   //多实例的
//@Scope(value = "singleton")  //单例
public class ESBServerSoapEndpointImpl implements ESBServerPortType {

    private static final Logger LOG = LoggerFactory.getLogger(ESBServerSoapEndpointImpl.class);
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private RedisLock redisLock;
//    @Autowired
//    private RedissonClient redissonClient;
    /* (non-Javadoc)
     * @see com.txqz.cxf.service.s30062000020.ESBServerPortType#op02(com.txqz.cxf.service.s30062000020.Req3006200002002Type req3006200002002)*
     */
    //@WebMethod(action = "whatIsTheAnswer")
    public Rsp3006200002002Type op02(Req3006200002002Type req) throws InterruptedException {
        LOG.info("Executing operation op02");

//        // Java对象转换成String类型的JSON字符串
//        JSONObject.toJSONString(Java对象)
//
//// String类型的JSON字符串转换成Java对象
//        JSONObject.toJavaObject(JSON字符串,Java对象.class)
//
//// Json字符串转换成JSONObject对象
//        JSONObject.parseObject(JSON字符串)
//
//// JSON字符串转换成Java对象
//        JSONObject.parseObject(JSON字符串,Java对象.class)
        RedissonClient redissonClient =redisLock.getRedissonClient(null,null,null,1);
        LOG.info("11111111");
        if(redisLock.redissondatabaselock(redissonClient,"aaaaaa",4000)){
            LOG.info("1获取锁");
        }else {
            LOG.info("没有获取锁");
        }
//        Thread.sleep(50000);
        LOG.info("22222222");
        redisLock.redissondatabaseunlock(redissonClient,"aaaaaa");
        LOG.info("3333333");
//        redisLock.redissonlock("11112",40000);
//        Thread.sleep(50000);
//        redisLock.redissonunlock("11112");
        if(redisLock.redissondatabaselock(redissonClient,"aaaaaa",40000))
            LOG.info("获取锁");
        Thread.sleep(50000);
        redisLock.redissondatabaseunlock(redissonClient,"aaaaaa");

        redisLock.lock(2,"abclog","tttt",30000);
        Thread.sleep(50000);
        redisLock.unlock(2,"abclog","tttt");





        //redisson lock
//        RLock lock = redissonClient.getLock("abclog");
//
//        try {
//            lock.lock(50, TimeUnit.SECONDS);
//            Thread.sleep(10000);
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            lock.unlock();
//        }

        int num = 8;

        LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory();
        System.out.println("bbbbb:"+connectionFactory.getDatabase());
        if (connectionFactory != null && num != connectionFactory.getDatabase()) {
            connectionFactory.setDatabase(num);
            this.redisTemplate.setConnectionFactory(connectionFactory);
            connectionFactory.resetConnection();
            connectionFactory.afterPropertiesSet();
        }
        System.out.println("aaaa:"+connectionFactory.getDatabase());
         //取出json字符串
        JSONObject jsonObject = JSONObject.parseObject((String)redisTemplate.opsForValue().get("key11"));
        System.out.println("1111111111" +jsonObject.get("abc"));

        String ABC =JSONObject.toJSONString( redisTemplate.opsForValue().get("key11"));
        System.out.println(ABC);

        //取出json嵌套json的字符串
        Map<String,Object>  map= new HashMap<String,Object>();
        map.put("cccc","adfadsfas");
        map.put("dddd","12312312312");
        Map<String,Object>  map1= new HashMap<String,Object>();
        map1.put("eeeee","123123");
        map1.put("vvvv","8282828");
        map.put("map",map1);
        redisTemplate.opsForValue().set("key12",JSONObject.toJSONString(map));
        JSONObject jsonObject1 = JSONObject.parseObject((String) redisTemplate.opsForValue().get("key12"));
        System.out.println("22222222" +jsonObject1.get("map"));
        JSONObject jsonObject2 = (JSONObject)jsonObject1.get("map");
        System.out.println(jsonObject2.get("vvvv"));





       //服务端存入，服务端取出
        Limitinfo limitinfo1 = new Limitinfo();
        limitinfo1.setJgh("9901");
        limitinfo1.setZqdm("291705");
        limitinfo1.setSyed("100000");

        Limitinfo limitinfo2 = new Limitinfo();
        limitinfo2.setJgh("0101");
        limitinfo2.setZqdm("291705");
        limitinfo2.setSyed("0");


        redisTemplate.opsForHash().put("limitinfo","291705000001",limitinfo1);
        redisTemplate.opsForHash().put("limitinfo","291705000002",limitinfo2);
        Limitinfo limitinfo11  = (Limitinfo) redisTemplate.opsForHash().get("limitinfo","291705000001");

        Limitinfo limitinfo22  = (Limitinfo) redisTemplate.opsForHash().get("limitinfo","291705000002");
        System.out.println("总行机构号:" +limitinfo11.getJgh());
        System.out.println("分行机构号:" +limitinfo22.getJgh());

        //客户端存入，服务端取出
        JSONObject cc  = JSONObject.parseObject((String) redisTemplate.opsForHash().get("limitinfo","291705000003"));
        Limitinfo limitinfo3 = JSONObject.toJavaObject(cc,Limitinfo.class);
        System.out.println("总行机构号:" +limitinfo3.getJgh());









        String s = JSONObject.toJSONString(req);
        System.out.println("参数输入------------------------------------------" + s);
        try {
            Rsp3006200002002Type resp = new Rsp3006200002002Type();
            //sysHead组装
            RspSysHeadType rspSysHeadType = new RspSysHeadType();
            rspSysHeadType.setReqSeq(req.getReqSysHead().getReqSeq()==null?"":req.getReqSysHead().getReqSeq());
            rspSysHeadType.setChannelID(req.getReqSysHead().getChannelID()==null?"":req.getReqSysHead().getChannelID());
            rspSysHeadType.setReqTime(req.getReqSysHead().getReqTime()==null?"":req.getReqSysHead().getReqTime());
            rspSysHeadType.setReqSysID(req.getReqSysHead().getReqSysID()==null?"":req.getReqSysHead().getReqSysID());
            rspSysHeadType.setReqDate(req.getReqSysHead().getReqDate()==null?"":req.getReqSysHead().getReqDate());
            rspSysHeadType.setDomainRef(req.getReqSysHead().getDomainRef()==null?"":req.getReqSysHead().getDomainRef());
            rspSysHeadType.setAcceptLang(req.getReqSysHead().getAcceptLang()==null?"":req.getReqSysHead().getAcceptLang());
            rspSysHeadType.setGlobalSeq(req.getReqSysHead().getGlobalSeq()==null?"":req.getReqSysHead().getGlobalSeq());
            rspSysHeadType.setOrgSysID(req.getReqSysHead().getOrgSysID()==null?"":req.getReqSysHead().getOrgSysID());
            rspSysHeadType.setSvcScn(req.getReqSysHead().getSvcScn()==null?"":req.getReqSysHead().getSvcScn());
            rspSysHeadType.setLegOrgID(req.getReqSysHead().getLegOrgID()==null?"":req.getReqSysHead().getLegOrgID());
            rspSysHeadType.setServiceID(req.getReqSysHead().getServiceID()==null?"":req.getReqSysHead().getServiceID());
            try {
                rspSysHeadType.setDomainRef(InetAddress.getLocalHost().getHostAddress());
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }

            //组装AppHeader
            RspAppHeadType rspAppHeadType = new RspAppHeadType();
            rspAppHeadType.setBrId(req.getReqAppHead().getBrId()==null?"":req.getReqAppHead().getBrId());
            rspAppHeadType.setTlrNo(req.getReqAppHead().getTlrNo()==null?"":req.getReqAppHead().getTlrNo());
            resp.setRspAppHead(rspAppHeadType);

            //组装local头
            RspLocalHeadType rspLocalHeadType = new RspLocalHeadType();
            rspLocalHeadType.setPDERTR("");
            rspLocalHeadType.setPDLDTC("");
            rspLocalHeadType.setPDTLSQ("");
            rspLocalHeadType.setPDTRCD(req.getReqLocalHead().getPDTRCD()==null?"":req.getReqLocalHead().getPDTRCD());
            rspLocalHeadType.setSYSDADDR(req.getReqLocalHead().getSYSDADDR()==null?"":req.getReqLocalHead().getSYSDADDR());
            rspLocalHeadType.setSYSMACFLAG(req.getReqLocalHead().getSYSMACFLAG()==null?"":req.getReqLocalHead().getSYSMACFLAG());
            rspLocalHeadType.setSYSPINSEED(req.getReqLocalHead().getSYSPINSEED()==null?"":req.getReqLocalHead().getSYSPINSEED());
            rspLocalHeadType.setSYSMKEYVER(req.getReqLocalHead().getSYSMKEYVER()==null?"":req.getReqLocalHead().getSYSMKEYVER());
            rspLocalHeadType.setSYSSEQNUM(req.getReqLocalHead().getSYSSEQNUM()==null?"":req.getReqLocalHead().getSYSSEQNUM());
            rspLocalHeadType.setSYSEFLAG(req.getReqLocalHead().getSYSEFLAG()==null?"":req.getReqLocalHead().getSYSEFLAG());
            rspLocalHeadType.setSYSMACSBNO(req.getReqLocalHead().getSYSMACSBNO()==null?"":req.getReqLocalHead().getSYSMACSBNO());
            resp.setRspLocalHead(rspLocalHeadType);

            //组装sendMessage
//            SendMessage sendMessage = new SendMessage();
//            sendMessage.setBizCategory(req.getReqAppBody().getBizCategory());
            //报文标签格式处理
            String msgContent = req.getReqAppBody().getMsgContent();
            String content = msgContent.replace("^|", "<");
            String replace = content.replace("|^", ">");
//            sendMessage.setMsgContent(replace);
//            sendMessage.setMsgId(req.getReqAppBody().getMsgID());
//            sendMessage.setMsgType(req.getReqAppBody().getMsgType());
//            sendMessage.setSendTime(req.getReqAppBody().getSendTime());
//            sendMessage.setDestCode(req.getReqAppBody().getDestCode());
//            if ("01".equals(sendMessage.getDestCode())) {
//                SendMessageServiceImpl sendMessageService = BeanUtils.getBean(SendMessageServiceImpl.class);
//                DCOTCMessage dcotcMessage = sendMessageService.getSendMessage(sendMessage);
                Rsp3006200002002Type.RspAppBody rspAppBody = new Rsp3006200002002Type.RspAppBody();
                rspAppBody.setRetCode("000000");
                rspAppBody.setErrMsg("成功");
//                String body = dcotcMessage.getBody();
//                String msg = body.replace("<", "^|");
//                String dcotc = msg.replace(">", "|^");
                rspAppBody.setBeiYong5("");
                rspAppBody.setBeiYong6("");
                rspAppBody.setBeiYong7("123123123");


                rspSysHeadType.setRetCode(rspAppBody.getRetCode());
                rspSysHeadType.setRetMsg(rspAppBody.getErrMsg()==null?"":rspAppBody.getErrMsg());
                resp.setRspSysHead(rspSysHeadType);
                resp.setRspAppBody(rspAppBody);
            //}
//            if ("02".equals(sendMessage.getDestCode())) {
//
//            }
//            if ("03".equals(sendMessage.getDestCode())) {
//            }
            String re = JSONObject.toJSONString(resp);
            System.out.println("参数结果输出------------------------------------------" + re);
            //Thread.sleep(1000*300);
            return resp;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

}
